package cn.ac.iscas.domain.job;

import com.iscas.datasong.lib.common.DataSongException;
import com.iscas.datasong.lib.common.Status;
import com.iscas.datasong.lib.util.DataSongStringUtils;

/**
 * Created by ISCAS on 2017/10/27.
 */
public enum ComponentType {
	reader("数据源"),      //数入源
	transformer("数据预处理"), //转换器，基础数据处理组件
	analyzer("数据分析"),    //数据分析模型组件
	writer("输出源"),      //输出源
	other("其他"),;       //其他组件，如流程控制等

	private String value;

	ComponentType(String value){
		this.value = value;
	}

	public String value() {
		return value;
	}

	static public ComponentType analyze(String value) throws DataSongException {
		if(DataSongStringUtils.isEmpty(value)){
			throw new DataSongException(Status.PARAM_ANALYZE_ERROR, "component type is null");
		}

		for(ComponentType type : ComponentType.values()){
			if(type.name().toUpperCase().equals(value.toUpperCase())){
				return type;
			}
		}

		throw new DataSongException(Status.PARAM_ANALYZE_ERROR, String.format("unknown component type [%s]", value));
	}
}
